<?php

namespace App\Services\Admin;

use App\Models\Community;
use App\Models\CommunityData;

class CommunityService
{
    // 获取小区
    public function getCommunityById($id)
    {
        return Community::findOrFail($id);
    }
    // 获取成交记录
    public function getCommunityDataById($id)
    {
        return CommunityData::with('community')->findOrFail($id);
    }
    //获取所有小区
    public function getAllCommunity($title,$limit=30)
    {
        $model = Community::query();
        if ($title){
            $model = $model->where('title','like','%'.$title.'%');
        }
        $res = $model->orderBy('created_at','desc')->paginate($limit)->toArray();
        $data = [
            'code' => 0,
            'msg'   => '正在请求中...',
            'count' => $res['total'],
            'data'  => $res['data']
        ];
        return response()->json($data);
    }
}